package com.schoolgard.action.system;

import com.schoolegard.services.MailConfigService;
import com.schoolgard.base.BaseAction;
import com.schoolgard.entitybean.MailConfig;
import com.supersystem.utils.JSONUtils;

public class MailConfigAction extends BaseAction{
	
	private MailConfigService mailConfigService;
	
	private MailConfig mailConfig;
	
	public void save(){
		MailConfig mail = null;
		if(mailConfig.getId() != null &&  mailConfig.getId() > 0) {
			mail = mailConfigService.findConfig();
			if(mail == null) {
				mail = new MailConfig();
			}
		}else{
			mail = new MailConfig();
		}
		mail.setServiceHost(mailConfig.getServiceHost());
		mail.setServiceAddress(mailConfig.getServiceAddress());
		mail.setUserName(mailConfig.getUserName());
		mail.setPassword(mailConfig.getPassword());
		mailConfigService.saveOrUpdate(mail);
		writeToResponse("1");
	}
	
	public void findConfig(){
		MailConfig config = mailConfigService.findConfig();
		writeToResponse(JSONUtils.toJSONString(config));
	}

	public void setMailConfigService(MailConfigService mailConfigService) {
		this.mailConfigService = mailConfigService;
	}

	public MailConfig getMailConfig() {
		return mailConfig;
	}

	public void setMailConfig(MailConfig mailConfig) {
		this.mailConfig = mailConfig;
	}

}
